package veterinaria.servlet.cliente;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import veterinaria.excepcion.DAOExcepcion;
import veterinaria.modelo.Cliente;
import veterinaria.negocio.GestionClientes;


/**
 * Servlet implementation class ClienteIngresarServlet
 */
@WebServlet("/ClienteIngresarServlet")
public class ClienteIngresarServlet extends javax.servlet.http.HttpServlet
implements javax.servlet.Servlet {
static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public ClienteIngresarServlet() {
    	super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String n = request.getParameter("dni");
		String a = request.getParameter("nombre");
		String b = request.getParameter("apePaterno");
		String c = request.getParameter("apeMaterno");
		String d = request.getParameter("email");
		String t = request.getParameter("direccion");
		String f = request.getParameter("telCasa");
		String g = request.getParameter("telMovil");
		String h = request.getParameter("foto");
		String i = request.getParameter("nota");
		
		GestionClientes negocio = new GestionClientes();
		try {
			Cliente cliente =negocio.insertar(n,a,b,c,d,t,f,g,h,i);
			
			if (cliente==null){
				response.sendRedirect(request.getContextPath()	+ "/ClienteError.jsp");
			}else{
				response.sendRedirect(request.getContextPath()	+ "/clienteSatis.jsp");
			}			
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}	
		

	}

}
